package com.tarena.lbs.business.servcie.Impl;

import com.tarena.lbs.business.dao.repository.BusinessCategoryRepository;
import com.tarena.lbs.business.pojo.po.BusinessCategoryPO;
import com.tarena.lbs.business.pojo.vo.BusinessCategoryVO;
import com.tarena.lbs.business.servcie.BusinessCategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
@Slf4j
public class BusinessCategoryServiceImpl implements BusinessCategoryService {
    @Autowired
    private BusinessCategoryRepository businessCategoryRepository;


    @Override
    public List<BusinessCategoryVO> allCategories() {
        log.info("查询所有分类");
        List<BusinessCategoryVO> businessCategoryVOS;
        List<BusinessCategoryPO> businessCategoryPOS = businessCategoryRepository.findAll();
        if (businessCategoryPOS.isEmpty()){
            return null;
        }
        businessCategoryVOS = new ArrayList<>();
        for (BusinessCategoryPO businessCategoryPO : businessCategoryPOS) {
            BusinessCategoryVO businessCategoryVO = new BusinessCategoryVO();
            businessCategoryVO.setId(businessCategoryPO.getId());
            businessCategoryVO.setLabel(businessCategoryPO.getLabel());
            businessCategoryVO.setSort(businessCategoryPO.getSort());
            businessCategoryVO.setStatus(businessCategoryPO.getStatus());
            businessCategoryVO.setRemark(businessCategoryPO.getRemark());
            businessCategoryVO.setCreateTime(businessCategoryPO.getCreateTime());
            businessCategoryVO.setUpdateTime(businessCategoryPO.getUpdateTime());
            businessCategoryVOS.add(businessCategoryVO);
        }
        return businessCategoryVOS;
    }
}
